package com.ln.controller.impl;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.util.WebUtils;

import com.ln.controller.BaseController;
import com.ln.pojo.impl.NotesPOJO;
import com.ln.pojo.impl.UserPOJO;
import com.ln.service.impl.NotesService;

/**
 * 新建
 * @author LINING
 *
 */
@Controller
@RequestMapping("new")
public class NewNoteController extends BaseController {
	@Autowired
	private NotesService notesService;
	
	@RequestMapping("code")
	public String newCode() {
		return "note/new-code";
	}
	
	@RequestMapping("code/sub")
	public String newCodeSub(HttpServletRequest request, NotesPOJO notesPOJO) {
		UserPOJO LOGIN_USER = (UserPOJO)WebUtils.getSessionAttribute(request, "LOGIN_USER");
		notesPOJO.setUser_id(LOGIN_USER.getId());
		notesPOJO.set_class(1);
		notesService.insert(notesPOJO);
		int notesId = notesService.selectId(LOGIN_USER.getId());
		return "redirect:/show/code/"+notesId;
	}

}
